<template>
  <!-- 扫码商品入库 -->
  <view class="stock-entry">
    <view class="info-card">
      <up-image :show-loading="true" :src="product.images ? product.images.split(',')[0] : '' " width="48px" height="48px" @click="click"></up-image>
      <view class="product-info">
        <view class="product-name">{{ product.name }}</view>
        <view class="product-code">条形码：{{ product.code }}</view>
      </view>
    </view>

    <view class="list-card">
      <view class="sku-item"  v-for="(item,index) in product.skuList" :key="index" @click="clickSku(item)">
        <view class="sku-item-left">
          <up-image :src="item.skuPic" width="28px" height="28px" ></up-image>
          <text class="spec">{{item.spec}}</text>
        </view>
        <up-icon name="arrow-right" color="#6a6a6a" size="18" :label="item.skuCode" labelPos="left" top="0" labelSize="12"></up-icon>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from "vue";
import { shopApi } from "@/api";
import { getStorage, setStorage } from "@/utils/storage";
const loading = ref(false);
const product = ref({})
const fromInfo = ref('')

const getScanCode = (code) => {
  shopApi.GETFRONTPRODUCTINSTOCKBYCODE({
    productSkuCode: code
  }).then((res) => {
    if (res.code != 200) {
      uni.showToast({
        title: res.errMsg,
        icon: "none"
      });
      return;
    }

    product.value = res.result
  });
}

const clickSku = (item) => {
  if(fromInfo.value == 'shouyin'){
    uni.navigateTo({
        url: "/pagesshop/scancodecashier/index?code=" + item.skuCode
    });
  }else{
    uni.navigateTo({
      url: '/pagesshop/inventory/scanpage?code='+ item.skuCode+'&from=skunum'
    })
  }
  
}

onLoad((options) => {
  console.log(options);

  if(options.code){
    getScanCode(options.code)
  }
  if(options.from){
    fromInfo.value = options.from
  }
});
</script>
<style lang="scss">
page {
  background-color: #f3f3f3;
}
</style>
<style lang="scss" scoped>

.sku-item{
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin-bottom:18px;
}
.sku-item-left{
  display: flex;
  align-items: center;
  .spec{
    margin-left:15px;
    font-size:12px;
  }
}

.list-card {
  background-color: #fff;
  border-radius: 12rpx;
  padding: 24rpx;
  box-sizing: border-box;
  margin-bottom: 20rpx;
}

.stock-entry {
  padding: 24rpx 24rpx 120rpx 24rpx;
  box-sizing: border-box;
  position: relative;
  box-sizing: border-box;
  .info-card {
    background-color: #fff;
    border-radius: 12rpx;
    padding: 24rpx;
    box-sizing: border-box;
    margin-bottom: 20rpx;
    display: flex;
  }

  .info-card {
    .product-info {
      margin-left: 20rpx;

      .product-name {
        font-size: 28rpx;
        color: #333;
        margin-bottom: 10rpx;
      }

      .product-code,
      .product-spec {
        font-size: 24rpx;
        color: #666;
        margin-bottom: 6rpx;

        &:last-child {
          margin-bottom: 0;
        }
      }
    }
  }

  .store-card {
    font-size: 28rpx;
    color: #333;
    background-color: #fff;
    border-radius: 12rpx;
    padding: 24rpx;
    margin-bottom: 20rpx;
    box-sizing: border-box;

    .store-name {
      font-size: 12px;
      font-weight: 400;
      line-height: 20px;
      color: rgba(0, 0, 0, 0.9);
      margin-bottom: 24rpx;
    }
  }

  .quantity-card {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .label {
      font-size: 28rpx;
      color: #333;
      margin-bottom: 20rpx;
      display: block;
    }

    .number-input {
      display: flex;
      align-items: center;
      justify-content: center;

      .btn {
        width: 56rpx;
        height: 56rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #f5f5f5;
        border: none;
        border-radius: 8rpx;

        &:active {
          opacity: 0.8;
        }

        &.disabled {
          opacity: 0.5;
          pointer-events: none;
        }

        text {
          font-size: 36rpx;
          color: #333;
        }
      }

      .input {
        width: 120rpx;
        height: 56rpx;
        text-align: center;
        margin: 0 20rpx;
        background-color: #f5f5f5;
        border: none;
        border-radius: 8rpx;
        font-size: 28rpx;
      }
    }
  }

  .footer {
    position: fixed;
    bottom: 20rpx;
    left: 0;
    right: 0;
    padding: 24rpx;
    background-color: #fff;
    box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
    z-index: 9;

    .confirm-btn {
      width: 100%;
      height: 80rpx;
      line-height: 80rpx;
      background-color: rgba(214, 142, 68, 1);
      color: #fff;
      border: none;
      border-radius: 40rpx;
      font-size: 32rpx;
      display: flex;
      justify-content: center;
      &:active {
        opacity: 0.9;
      }
    }
  }

  .success-page {
    position: fixed;
    top: 0;
    left: 0;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 120rpx 40rpx;
    box-sizing: border-box;
    z-index: 99;
    width: 100%;
    height: 100vh;
    .success-icon {
      margin-bottom: 40rpx;
    }

    .success-text {
      font-size: 36rpx;
      color: #333;
      font-weight: bold;
      margin-bottom: 100rpx;
    }

    .button-group {
      width: 100%;
      display: flex;
      flex-direction: column;
      gap: 20rpx;
      .action-btn {
        width: 100%;
        height: 88rpx;
        line-height: 88rpx;
        border-radius: 44rpx;
        font-size: 32rpx;
        border: none;

        &.primary-btn {
          background-color: rgba(214, 142, 68, 1);
          color: #fff;
        }

        &.secondary-btn {
          background-color: rgba(253, 236, 219, 1);
          color: rgba(214, 142, 68, 1);
        }
      }
    }
  }
}
</style>
